<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      screenshotUpload: true,
      dataFormConfig: {
        id: {
          hidden: true
        },
        productNo: {
          label: '中套型号',
          placeholder: '请输入中套型号'
        },
        unitPrice: {label: '价格', type: 'number'},
        bottleOutDiameter: {
          label: '口径',
          placeholder: '请输入口径',
          default: "1口"
        },
        productWeight: {
          label: '克重(g)',
          type: 'number',
          max: 1000,
          default: 0
        },
        productImageId: {
          label: '产品图片',
          type: 'uploadScreenshot',
          imageType: 'uploadProductImage'
        },
        relateColor: {
          label: '颜色',
          placeholder: '请输入颜色'
        },
        relateMaterial: {
          label: '材质',
          placeholder: '请输入材质'
        },
        relateSize:{
          label: '尺寸',
          placeholder: '请输入尺寸'
        },

        boxPackingQuantity: { label: '装箱数量', type: 'number' },
        grossWeight: { label: '毛重',       type: 'number' },
        boxCartonSize: { label: '箱规(cm)' },
        productDrawingId: {
          label: '产品图纸',
          type: 'uploadImage',
          imageType: 'uploadProductPaper'
        },
        remark: {
          label: '备注',
          inputType: 'textarea',
          placeholder: '请输入产品备注'
        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    init(id, property, cb) {
      this.dataForm.id = id || 0
      /**
       * 1  裸瓶
       * 2  盖子
       * 3  喷头
       * 4  中套
       * 5  披肩
       * 99  其他
       * @type {number}
       */
      this.dataForm.productCategoryId =4
      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        stepsConfig: this.stepsConfig,
        dataRule: this.getNeedDataRule('productNo', 'status',  'bottleOutDiameter'),
        initApi: 'productApi/productInfoInfo',
        saveApi: 'productApi/saveProductInfo',
        updateApi: 'productApi/updateProductInfo',
        objectName: 'productInfo',
        submitCallback: cb,
        screenshotUploadFlag: true
      })

      this.$nextTick(() => {
        if (!this.R.isNil(property)) {
          Object.keys(property).forEach((key) => {
            this.dataForm[key] = property[key]
          })
        }
      })
    }
  }
}
</script>
